package com.qf.day11;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Random;

class StrIterator implements Iterator<String> {
    private List<String> strings;
    private int currentIndex = 0;

    public StrIterator(List<String> strings) {
        this.strings = strings;
    }

    @Override
    public boolean hasNext() {
        return currentIndex < strings.size();
    }

    @Override
    public String next() {
        return strings.get(currentIndex++);
    }

    // 可能还有其他方法，比如 remove() 等，这里省略了
}

public class RandomStringFromIterator {
    private static final Random RANDOM = new Random();

    public static void main(String[] args) {
        // 初始化字符串集合
        List<String> stringPool = new ArrayList<>();
        stringPool.add("Hello");
        stringPool.add("World");
        stringPool.add("Java");
        stringPool.add("Program");
        // ... 添加更多字符串到集合中

        // 创建 StrIterator 实例
        StrIterator strIterator = new StrIterator(stringPool);

        // 生成10个随机的字符串
        for (int i = 0; i < 10; i++) {
            // 随机选择一个索引（注意：这里假设集合足够大，不会越界）
            int randomIndex = RANDOM.nextInt(stringPool.size());

            // 重置 StrIterator 到开始位置
            strIterator = new StrIterator(stringPool);

            // 遍历到随机索引的位置
            for (int j = 0; j < randomIndex; j++) {
                strIterator.next();
            }

            // 获取随机字符串
            String randomString = strIterator.next();
            System.out.println(randomString);
        }
    }
}
